//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类;

public class demo_209 {
    public demo_209() {
    }

    public static void main(String[] args) {
        int target = 11;
        int[] nums = new int[]{1, 2, 3, 4, 5};
        System.out.println(minSubArrayLen(target, nums));
    }

    public static int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int right = 0;
        int count = nums[0];
        int sum = 0;

        while(right < nums.length) {
            if (count < target) {
                if (right + 1 >= nums.length) {
                    break;
                }

                ++right;
                count += nums[right];
            } else if (count == target || count > target) {
                if (right - left < sum || sum == 0) {
                    sum = right - left + 1;
                }

                count -= nums[left];
                ++left;
            }
        }

        return sum;
    }
}
